/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.panomedic.core;

import com.panomedic.log4j.LogCategories;
import com.panomedic.log4j.Logger;
import java.util.ArrayList;

/**
 *
 * @author Yare
 */
public class MappingValuesList extends ArrayList<Double> {
    
    static Logger logger = new Logger();

    public double getAverage(){
        if (this.size() == 0)
            return -1;
        double sum = 0;
        for (int i = 0; i < this.size(); i++) {
             sum += (Double)this.get(i);
//             some kind of weighting (border values)
        }
        sum /= this.size();
        return sum;
    }
    
    public double setAverage(){
        double avg = getAverage();
        if (avg != -1) {
            this.clear();
            this.add(avg);
        }
        return avg;
        
    }
    
    
    public static void main(String[] args){
        MappingValuesList list = new MappingValuesList();
        list.add(12.2);
        list.add(23.5);
        list.add(102.3);
        double avg = list.getAverage();
        logger.debug(LogCategories.IMAGEIO, "Avg: "+avg);
        
    }
}

